package com.bsoft.hospitalchs.service;

import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;

import com.bsoft.hospitalchs.R;
import com.bsoft.hospitalchs.utils.LogUtil;

/**
 * Created by 泅渡者
 * Created on 2017/6/18.
 */

public class UploadService extends Service {

    public  static final String TAG= "UploadService";

    private ServiceBinder  mService = new ServiceBinder();

    private final int NotificationID = 0x10000;

    private NotificationManager mNotificationManager = null;

    private NotificationCompat.Builder builder;

    private Intent mIntent;

    @Override
    public void onCreate() {
        super.onCreate();
        LogUtil.e(TAG,"服务创建");
        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        builder = new NotificationCompat.Builder(getApplicationContext());
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setTicker("正在下载新版本");
        builder.setContentTitle("晞景儿童");
        builder.setContentText("正在下载,请稍后...");
        builder.setNumber(0);
        builder.setAutoCancel(true);
        mNotificationManager.notify(NotificationID, builder.build());
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        LogUtil.e(TAG,"执行服务");
        mIntent = intent;
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return mService;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        LogUtil.e(TAG,"服务停止");
    }

   public class ServiceBinder extends Binder{

        public void startUpload(){
            String url = mIntent.getStringExtra("url");
            LogUtil.e(TAG,url);
        }
    }
}
